package com.cloud.two.ribbon.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * @author henryGui
 * @version V1.0
 * @Title: HelloService
 * @Package com.cloud.two.ribbon.service
 * @Description: TODO
 * @date 2018-06-18 下午2:00
 */
@Service
public class HelloService {

    @Autowired
    RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "hiError")
    public String hiService(String name) {

        return restTemplate.getForObject("http://SERVICE-HI/hi?name=" + name, String.class);
    }

    public ResponseEntity hiService1(String name) {
        HttpEntity entity = new HttpEntity("9999999");

        return restTemplate.postForEntity("http://personal-dubbo-cpic/hi", "9999999", String.class);

//        return restTemplate.exchange("http://personal-dubbo-cpic/hi", HttpMethod.POST, entity, String.class);


    }

    public ResponseEntity hiService2() {
        Map map=new HashMap();
        map.put("name","ffgfg");
        return restTemplate.postForEntity("http://personal-cloud-provider-api/channel/list", map, String.class);


    }


    public String hiError(String name) {
        return "hi," + name + ",sorry,error!";
    }

}
